package com.spzx.channel.controller;

import com.spzx.channel.service.IndexService;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.SpzxCache;
import com.spzx.product.domain.SkuQuery;
import com.spzx.product.domain.vo.ProductSkuDetailsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
@Tag(name = "首页模块")

public class IndexController extends BaseController {
    @Resource
    IndexService indexService;
    //浏览器 访问/channel/index的请求交给网关后，会跳过一级路径
    @GetMapping("index")
    public AjaxResult index(){
        return success(indexService.selectIndexData());
    }


    @GetMapping("category/tree")
    public AjaxResult categoryTree(){
        return success(indexService.selectCategoryTree());
    }

    @GetMapping("list/skuList/{pageNum}/{pageSize}")
    public TableDataInfo skuList(SkuQuery skuQuery){

        return indexService.selectProductDetail(skuQuery).getData();
    }


    @Operation(summary = "查询商品详情")
    @GetMapping("/item/{skuId}")
    @SpzxCache(lockKeyPrefix = "spzx:channel:sku:lock:",cacheKeyPrefix = "spzx:channel:cache:sku:")
    public AjaxResult getSkuDetails(@PathVariable Long skuId){
        ProductSkuDetailsVO vo = indexService.selectSkuDetails(skuId);
        return success(vo);
    }

}